<?
    /**
     * Smarty plugin
     * @package Smarty
     * @subpackage plugins
     * @author Kulikov Alexey <a.kulikov@gmail.com>
     */


    /**
     * Smarty {load_site_stats} function plugin
     *
     * Type:     function
     * Name:     load_site_stats
     * Purpose:  Loads the solution usage statistics
     *   @param array
     *   @param Smarty
     *
     * This smarty plugin can be talked to using the following
     * template parameters:
     *   
     *   * var (string) -- name of variable where to load the 
     *                     data tree to
     *                     >> default: stats
     *
     * @return string
     */
    function smarty_function_load_site_stats($params, &$smarty){
        global $db; // create a link to the database connection

        //pre-process parameters
        //variable name
        if(empty($params['var'])){
            $var = 'stats';
        }else{
            $var = $params['var'];
        }

        //select the user data
        $data                   = array();
        $data['pages']          = $db->getOne("SELECT count(*) FROM pagemap");
        $data['publishedPages'] = $db->getOne("SELECT count(*) FROM pagemap WHERE wf_state = 1");
        $data['folders']        = $db->getOne("SELECT count(*) - 1 FROM structure");
        $data['admins']         = $db->getOne("SELECT count(*) FROM user_in_group WHERE gid < 1000");
        $data['users']          = $db->getOne("SELECT count(*) FROM user_access");
        $data['created']        = $db->getOne("SELECT created FROM objectmap ORDER BY created ASC LIMIT 1");
        $data['modified']       = $db->getOne("SELECT modified FROM objectmap ORDER BY modified DESC LIMIT 1");

        //give all this shit to smarty
        $smarty->assign($var,$data);
    }
?>